<?php
	session_start();

	include("mysql_connect.php");
	
	$strKeyWord = $_POST['strLocation'];
	$isSale = $_POST['isSale'];
	
	$strSqlCommand = 'SELECT COUNT(*) 
						FROM ResidentialProperty tbRP
						LEFT JOIN Listing tbLT			ON tbRP.Listing_idListing = tbLT.idListing
						LEFT JOIN StreetAddress tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress
						LEFT JOIN ListingData tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
						LEFT JOIN CurrencyFormat tbPR	ON tbLD.Price = tbPR.idCurrencyFormat
						LEFT JOIN Baths tbBT			ON tbBt.idBaths = tbRp.Baths_idBaths
						LEFT JOIN Rooms tbRM			ON tbRm.idRooms = tbRp.Rooms_idRooms
					  	WHERE PostalCode = "'. $strKeyWord.'"';// . " LIMIT 0, 50";
//	$strSqlCommand .= " OR City LIKE '%".$strKeyWord."%'";
	$strSqlCommand .= ' AND isSale = '. $isSale;
	$result = mysql_query($strSqlCommand);
	
	//echo $strSqlCommand."<br/>";
	$rowCount = @mysql_fetch_row($result);
	
	$_SESSION['StrItem'] = 0;
	$_SESSION['MaxItem'] = $rowCount[0] - 6;
	
	$_SESSION['SearchKey'] = "SELECT idResidentialProperty, idListing, Currency, TotalRooms, BathTotal, StreetNumber, StreetDirPrefix, StreetName, UnitNumber, City, StateOrProvince, PostalCode
								FROM ResidentialProperty tbRP
								LEFT JOIN Listing  tbLT			ON tbRP.Listing_idListing = tbLT.idListing
								LEFT JOIN StreetAddress  tbSA	ON tbLT.StreetAddress_idStreetAddress = tbSA.idStreetAddress
								LEFT JOIN ListingData  tbLD		ON tbLT.ListingData_idListingData = tbLD.idListingData
								LEFT JOIN CurrencyFormat  tbPR	ON tbLD.Price = tbPR.idCurrencyFormat
								LEFT JOIN Baths  tbBT			ON tbBt.idBaths = tbRp.Baths_idBaths
								LEFT JOIN Rooms  tbRM			ON tbRm.idRooms = tbRp.Rooms_idRooms
								WHERE tbSA.PostalCode = '". $strKeyWord."'";
//	$_SESSION['SearchKey'] .= " OR City LIKE '%".$strKeyWord."%'";
	$_SESSION['SearchKey'] .= ' AND isSale = '. $isSale;
//						LIMIT ".$_SESSION['StrItem'].", 6";
	
	$result = mysql_query($_SESSION['SearchKey'] ." LIMIT ".$_SESSION['StrItem'].", 6");
	
	$_SESSION["MapAddress"] = 'https://maps.googleapis.com/maps/api/staticmap?center=';
	$nIdx = 0;
	while($rowDetail = @mysql_fetch_array($result))	
	{// URL, Price,idListing
				echo '<a class="ViewDetailBlock" id="'.$rowDetail['idResidentialProperty'].'" href="#page14">';
		echo '<div class="ui-grid-a ">';
			echo '<div class="ui-block-a property-image">';
					echo '<img src="http://23.21.84.9/images/Residential_Photo/Photo'.$rowDetail['idListing'].'-1.jpeg"/>';
			echo '</div>';
		
		$strAddress = $rowDetail['StreetNumber']. '+'.$rowDetail['StreetName'] . '+' . $rowDetail['City'];// . '+' . $rowDetail['StateOrProvince'];
		if($nIdx == 0)
		{
			$_SESSION["MapAddress"] .= $strAddress . "&zoom=11&size=288x400";
		}
		$nIdx++;
		$_SESSION["MapAddress"] .= "&markers=label:".$nIdx."%7C".$strAddress;		
//		$strSqlCommand = "SELECT ThePrice FROM Price
//						  WHERE idPrice = ".$rowDetial[1];		
//		$resultPrice = mysql_query($strSqlCommand);
//		$rowPrice = @mysql_fetch_row($resultPrice);

			echo '<div class="ui-block-b property-description">';
				echo '<div>';
					echo "<p>".$rowDetail['StreetNumber']." ".$rowDetail['StreetName']." ".$rowDetail['UnitNumber']."</p>";
					echo "<p>".$rowDetail['City'].", ".$rowDetail['StateOrProvince'].", ".$rowDetail['PostalCode']."</p>";
					//echo "<p>".$rowType[0]." Bedrooms, ".$rowType[1]." Bathrooms</p>";
					echo "<p>".$rowDetail['TotalRooms']." Bedrooms, ".$rowDetail['BathTotal']." Bathrooms</p>";
					echo "<p>".$rowDetail['Currency']."</p>";
				echo "</div>";

		//$_SESSION["PropertyId"] = $rowType[2];
//		$_SESSION["PropertyId"] = $rowDetial[4];
//			$strAddress = $rowAddress[1]. ' '.$rowAddress[3] . ' ' . $rowAddress[5] . ' ' . $rowAddress[6];
//		$_SESSION["MapAddress"] = str_replace( " ","+", $strAddress);
			//echo '<input type="hidden" id="Property" value="'.$rowType[2].'">';
			//echo '<input type="hidden" class="Property" value="'.$rowDetial[4].'">';
			echo '</div>';
		echo '</div>';//class="ui-grid-a"
				echo '</a>';
			
/*	
		echo '<div class="ui-grid">';
			echo '<a data-role="button" data-transition="fade" href="#page14" class="ui-btn ui-shadow ui-btn-corner-all ui-btn-up-c PropertyDetail">';
			// data-corners="true" data-shadow="true"
			//data-iconshadow="true" data-iconsize="18" data-wrapperels="span" data-theme="c" 
			//
			echo '<input type="hidden" value="'.$rowDetial[4].'" class="Property"/>';
			echo '<span class="ui-btn-inner ui-btn-corner-all"><span class="ui-btn-text">';
			echo "View Details";
			echo '</span></span>';
			echo '</a>';
		
		echo '</div>';
*/	//echo '</div>';//<!-- /grid-a -->";//<div><p></p></div>';
		//

	}
	$_SESSION["MapAddress"] .= "&sensor=false";
?>